<script lang="ts" setup>
import { computed } from 'vue'
const props = defineProps<{
  power: number
  inputVoltage: string
}>()
const powerHeight = computed(() => {
  return (88 / 100) * props.power + 'px'
})
</script>

<template>
  <div class="battery" flex items-center>
    <div class="battery-body">
      <span class="battery-powerlevel">{{ power }}%</span>
      <div
        class="battery-power"
        :style="[{ background: power > 20 ? '#23B5AF' : '#EFA14E' }, { width: powerHeight }]"
      />
    </div>
    <div class="battery-head" />
    <div class="battery-inputVoltage">
      <span>{{ inputVoltage }}</span>
    </div>
  </div>
</template>

<style scoped lang="scss">
.battery {
  position: relative;
  .battery-body {
    width: 100px;
    height: 39px;
    background: #ffffff;
    border: 2px solid #051127;
    border-radius: 4px;
    padding: 4px 4px;
    box-sizing: border-box;
    line-height: 31px;
    display: flex;
    align-items: center;
    .battery-powerlevel {
      font-size: 17px;
      font-family: Arial;
      line-height: 19px;
      color: #010d25;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      z-index: 999;
    }
    .battery-power {
      z-index: 100;
      height: 100%;
    }
  }
  .battery-head {
    width: 5px;
    height: 18px;
    background: #051127;
    border-radius: 0px 2px 2px 0px;
  }
  .battery-inputVoltage {
    width: 32px;
    position: absolute;
    left: 0px;
    top: 0px;
    background: #5892fb;
    border-radius: 4px 0px 8px 0px;
    font-size: 12px;
    font-family: Arial;
    line-height: 16px;
    color: #ffffff;
    text-align: center;
    z-index: 101;
  }
}
</style>
